﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace Mindfor.Web.Data
{
	/// <summary>
	/// Represents entity with int-id.
	/// </summary>
	[Serializable]
	public class IdEntity
	{
		/// <summary>
		/// Gets or sets id.
		/// </summary>
		public virtual int Id { get; set; }

		/// <summary>
		/// Determines whether the specified object type equals to current type and Id proeprties matches.
		/// </summary>
		/// <param name="obj">Object to compare.</param>
		/// <returns>True, if objects equals. Otherwise false.</returns>
		public override bool Equals(object obj)
		{
			if (obj != null && this.GetType() != obj.GetType())
				return false;
			
			IdEntity obj1 = (IdEntity)obj;
			return Id == obj1.Id;
		}

		/// <summary>
		/// Serves as a hash function for a particular type.
		/// </summary>
		/// <returns>A hash code for the current System.Object.</returns>
		public override int GetHashCode()
		{
			return (GetType().FullName + Id).GetHashCode();
		}
	}
}
